package com.ibm.cloud.banking.sample.saga;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.SagaPropagation;
import org.springframework.context.annotation.Configuration;

/**
 * PCS 调用自动化正向反向PBS样例
 *
 * @author HanDong
 * @date 2022/7/26
 */
@Configuration
public class SagaSampleRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("direct:PCS-SAMPLE")
                .routeId("PCS-SAMPLE")
                .saga()
//                .option("source-body",body())
                .propagation(SagaPropagation.REQUIRES_NEW)
                .process(exchange ->
                {
                    exchange.setProperty("source-body",exchange.getIn().getBody());
                })
                .to("direct:PBS000001")
                .process(exchange ->
                {
                    exchange.getIn().setBody(exchange.getProperty("source-body"));
                })
                .to("direct:PBS000002")
                .process(exchange ->
                {
                    exchange.getIn().setBody(exchange.getProperty("source-body"));
                })
                .to("direct:PBS000003")
                .to("direct:finalize");
    }
}
